from apps.forms import FormMixin
from django import forms
from .models import News
from apps.news.models import Banner
from apps.course.models import Course


# 编辑新闻分类的表单验证
class EditNewsCategoryForm(forms.Form, FormMixin):
    pk = forms.IntegerField(error_messages={"required": '必须传入主键！'})
    name = forms.CharField(max_length=100)


# 新增新闻的表单验证
class WriteNewsForm(forms.ModelForm, FormMixin):
    category = forms.IntegerField()

    class Meta:
        model = News
        exclude = ['category', 'author', 'pub_time']


# 添加轮播图的表单验证
class AddBannerForm(forms.ModelForm, FormMixin):
    class Meta:
        model = Banner
        fields = ['priority', 'link_to', 'image_url']


# 编辑轮播图的表单验证
class EditBannerForm(forms.ModelForm, FormMixin):
    pk = forms.IntegerField()

    class Meta:
        model = Banner
        fields = ['priority', 'link_to', 'image_url']


# 编辑新闻的表单验证
class EditNewsForm(forms.ModelForm, FormMixin):
    category = forms.IntegerField()
    pk = forms.IntegerField()

    class Meta:
        model = News
        exclude = ['category', 'author', 'pub_time']


# 发布课程的表单验证
class PubCourseForm(forms.ModelForm, FormMixin):
    category_id = forms.IntegerField()
    teacher_id = forms.IntegerField()

    class Meta:
        model = Course
        exclude = ['category', 'teacher']
